package leetcode;

public class p100判断两棵树是否相同 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        //都是空树则相等
        if (p==null && q==null) {
            return true;
        }
        //一空一不空则不相等
        if(p==null || q==null) {
            return false;
        }
        //根结点值不相等即false
        if(p.val != q.val) {
            return false;
        }
        //左子树不相等即false
        if (!isSameTree(p.left , q.left)) {
            return false;
        }
        //右子树不相等即false

        return isSameTree(p.right , q.right);

    }
}
